package org.apache.servicecomb.samples.practise.houserush.user.center.aggregate;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;

import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;


import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author: Snake Man
 * @system: 楼盘实体类
 * @DateTime: 2021/12/28 18:17
 * @Description: todo 删除时间
 */
@Data
@Entity
@Table(name = "realestates")
@SQLDelete(sql = "update realestates set deleted_at = now() where id = ?")
@Where(clause = "deleted_at is null")
@EntityListeners(AuditingEntityListener.class)
public class Realestate {

    @Id
    @GeneratedValue(strategy =  GenerationType.AUTO)//声明生成主键方式
    private int id;

    //@Column 字段映射
    private String name;
    private String description;

    @Temporal(TemporalType.TIMESTAMP)
    private Date deletedAt;

    @CreatedDate
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdAt;

    @LastModifiedDate
    @Temporal(TemporalType.TIMESTAMP)
    private Date updatedAt;

    private String address;
    private String type;
    private String avgprice;
    private String useyear;
    private String usernum;
    private String area;
    private String buildname;

    //可以实现循环阻断，解决相互循环的问题
    //value的值配置的就是，序列化时忽略realestate。那么在进行buildings属性序列化
    //的时候，就不会再对buildings里面的realestate(楼盘)进行序列化了。
    @JsonIgnoreProperties(ignoreUnknown = true, value = {"realestate"})
    //配置一对多
    @OneToMany(mappedBy = "realestate")
    private List<Building> buildings = new ArrayList<>();
}
